<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>资源管理列表</title>
	<%@ include file="../../include/head.jsp"%>
	<link rel="stylesheet" href="${ctxStatic}/3rd-lib/jquery-ztree/css/zTreeStyle.css">
</head>
<body>
<div class="admin-content">
	<div class="am-g">
		<div class="am-u-sm-3">
			<div class="am-panel am-panel-default">
				<div class="am-panel-hd">资源菜单</div>
				<div class="am-panel-bd">
					<div class="am-scrollable-horizontal">
						<ul id="tree" class="ztree"></ul>
					</div>
				</div>
			</div>
		</div>

		<div class="am-u-sm-9">
			<div class="am-panel am-panel-default">
				<div class="am-panel-hd">
					<c:if test="${page.entity.id!='0'}"><button type="button" class="am-btn am-btn-xs" onclick="history.back()"><span class="am-icon-arrow-left"></span></button></c:if>
					资源列表
					<button type="button" class="am-btn am-btn-primary am-btn-xs iu-right" onclick="openModel('新增','${ctx}/resource/create?id=${page.entity.id}')"><span class="am-icon-plus"></span> 新增</button>
				</div>
				<div class="am-panel-bd">
					<div class="am-g">
						<form id="searchForm" action="${ctx}/resource" method="post" style="display: none;">
							<input type="hidden" name="id" value="${page.entity.id}" />
							<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
							<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
						</form>
						<div class="am-u-sm-12">
							<table class="am-table am-table-striped am-table-hover table-main">
								<thead>
								<tr>
									<th>序号</th>
									<th>上级节点</th>
									<th>资源名称</th>
									<th>资源类型</th>
									<th>访问路径</th>
									<th>是否可用</th>
									<th>权限标识</th>
									<shiro:hasPermission name="sys:resource:edit"><th>操作</th></shiro:hasPermission>
								</tr>
								</thead>
								<tbody>
								<c:forEach items="${page.list}" var="resource" varStatus="status">
									<tr>
										<td>${status.index+1}</td>
										<td><c:choose><c:when test="${empty resource.resource.name}">根节点</c:when><c:otherwise>${resource.resource.name}</c:otherwise></c:choose></td>
										<td>${resource.name}</td>
										<td><span class="am-badge am-badge-primary am-radius">${resource.type.info}</span></td>
										<td>${resource.url}</td>
										<td>${resource.available?'<span class="am-badge am-badge-success am-radius">可用</span>':'<span class="am-badge am-badge-danger am-radius">禁用</span>'}</td>
										<td>${resource.permission}</td>
										<shiro:hasPermission name="sys:resource:edit"><td>
											<div class="am-btn-toolbar">
												<div class="am-btn-group am-btn-group-xs">
													<button class="am-btn am-btn-default am-btn-xs am-text-primary am-hide-sm-only" onclick="openModel('编辑','${ctx}/resource/update?id=${resource.id}')"><span class="am-icon-pencil"></span> 编辑</button>
													<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="iuConfirm('确认要删除该条数据吗？', '${ctx}/resource/delete?id=${resource.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}')"><span class="am-icon-trash-o"></span> 删除</button>
												</div>
											</div>
										</td></shiro:hasPermission>
									</tr>
									</tr>
								</c:forEach>
								</tbody>
							</table>
						</div>
						<div class="am-u-sm-12">
							<%@ include file="../../utils/pagination.jsp" %>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<%@ include file="../../include/bottom.jsp"%>
<script src="${ctxStatic}/3rd-lib/jquery-ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script>
	$(function () {
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			callback : {
				onClick : function(event, treeId, treeNode) {
					location.href = "${ctx}/resource?id="+treeNode.id;
				}
			}
		};
		//获取机构树
		get("${ctx}/resource/tree",function(data){
			var resources =[];
			for(var i=0;i<data.length;i++){
				var resource = {};
				resource.name = data[i].name;
				resource.id = data[i].id;
				resource.pId = data[i].parentId;
				resources.push(resource);
			}
			var ztree = $.fn.zTree.init($("#tree"), setting, resources);
			ztree.expandAll(true);
		});
	});
</script>
<script>
	$(document).ready(function () {
		var msg = '${msg}';
		if(msg!=''){
			iuMsg(msg);
		}
	});
</script>
</body>
</html>